/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cp2013;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JScrollPane;

/**
 *
 * @author AcerXPS
 */
public class PlaceItemUI extends JPanel {

    private JLabel lblName;
    private JTextField txtItemName;
    private JLabel lblDesc;
    private JTextArea txtDescription;
    private JLabel lblFinishD;
    private JTextField txtFinishDate;
    private JLabel lblFormat;
    private JLabel lblStartBid;
    private JTextField txtStartBid;
    private JLabel lblToken;
    private JButton btnSubmit;
    private JButton btnCancel;
    private File f;
    private BufferedImage img;

    @Override
    public void paintComponent(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.drawRenderedImage(img, AffineTransform.getTranslateInstance(0, 0));
    }
    public void initiatePlaceItemUI() {
        try{
            f = new File("Item.jpg");
            img = ImageIO.read(f);
        }catch (IOException ex){
            Logger.getLogger(RegisterUI.class.getName()).log(Level.SEVERE, null, ex);
        } finally{
         setBackground(Color.white);
        setLayout(null);
        setAlignmentY(JPanel.CENTER_ALIGNMENT);
        initiateLabels();
        }

    }//end of initiateRegisterUI

    private void initiateLabels() {
        lblName = new JLabel("Item Name: ");
        lblName.setBounds(60, 100, 120, 15);
        setTxtItemName(new JTextField(15));
        getTxtItemName().setBounds(180, 100, 120, 20);


        lblDesc = new JLabel("Description: ");
        lblDesc.setBounds(60, 130, 120, 15);
        setTxtDescription(new JTextArea(120, 5));
        getTxtDescription().setLineWrap(true);
        getTxtDescription().setWrapStyleWord(true);
        JScrollPane descScroller = new JScrollPane(getTxtDescription());
        descScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        descScroller.setBounds(180, 130, 200, 90);

        lblFinishD = new JLabel("Finish Date: ");
        lblFinishD.setBounds(60, 230, 120, 15);
        setTxtFinishDate(new JTextField(15));
        getTxtFinishDate().setBounds(180, 230, 120, 20);
        lblFormat = new JLabel("YYYY/MM/DD");
        lblFormat.setBounds(310, 230, 80, 15);
        
        lblStartBid = new JLabel("Starting Bid: ");
        lblStartBid.setBounds(60, 260, 120, 15);
        setTxtStartBid(new JTextField(15));
        getTxtStartBid().setBounds(180, 260, 80, 20);
        lblToken = new JLabel("Token");
        lblToken.setBounds(270, 260, 120, 15);

        btnSubmit = new JButton("Submit!");
        btnSubmit.setBounds(80, 310, 80, 20);
        btnCancel = new JButton("Cancel");
        btnCancel.setBounds(180, 310, 80, 20);

        add(lblName);
        add(getTxtItemName());
        add(lblDesc);
        add(descScroller);
        add(lblFinishD);
        add(getTxtFinishDate());
        add(lblFormat);
        add(lblStartBid);
        add(getTxtStartBid());
        add(lblToken);
        add(btnSubmit);
        add(btnCancel);
    }


    public JButton getBtnSubmit() {
        return btnSubmit;
    }

    public JButton getBtnCancel(){
        return btnCancel;
    }


    public void addListeners(ActionListener placeItemListener) {
        btnSubmit.addActionListener(placeItemListener);
        btnCancel.addActionListener(placeItemListener);
    }

    /**
     * @return the itemName
     */
    public JTextField getTxtItemName() {
        return txtItemName;
    }

    /**
     * @param itemName the itemName to set
     */
    public void setTxtItemName(JTextField itemName) {
        this.txtItemName = itemName;
    }

    /**
     * @return the description
     */
    public JTextArea getTxtDescription() {
        return txtDescription;
    }

    /**
     * @param description the description to set
     */
    public void setTxtDescription(JTextArea description) {
        this.txtDescription = description;
    }

    /**
     * @return the finishDate
     */
    public JTextField getTxtFinishDate() {
        return txtFinishDate;
    }

    /**
     * @param finishDate the finishDate to set
     */
    public void setTxtFinishDate(JTextField finishDate) {
        this.txtFinishDate = finishDate;
    }

    /**
     * @return the startBid
     */
    public JTextField getTxtStartBid() {
        return txtStartBid;
    }

    /**
     * @param startBid the startBid to set
     */
    public void setTxtStartBid(JTextField startBid) {
        this.txtStartBid = startBid;
    }
}
